package com.fw.service.outboundmessagelog.impl;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.fw.service.outboundmessagelog.OutboundMessageLogService;
import com.fw.service.outboundmessagelog.bean.OutboundMessageLogBean;
import com.fw.service.persistence.dao.OutboundMessageLogDAO;
import com.fw.service.persistence.dto.OutboundMessageLog;
import com.fw.util.DateUtils;
import com.fw.util.StringUtils;

public class OutboundMessageLogServiceImpl implements OutboundMessageLogService {

    @Autowired
    private OutboundMessageLogDAO outboundMessageLogDAO;

    @Override
    public OutboundMessageLogBean createOutboundMessageLog(OutboundMessageLogBean outboundMessageLogBean) {
	OutboundMessageLogBean returnOutboundMessageLogBean = null;
	if (outboundMessageLogBean != null) {
	    OutboundMessageLog outboundMessageLog = new OutboundMessageLog();
	    BeanUtils.copyProperties(outboundMessageLogBean, outboundMessageLog);
	    Date currentDate = DateUtils.getCurrentDate();
	    outboundMessageLog.setDateTime(StringUtils.formatDate(currentDate, StringUtils.PATTERN_DATETIME_PERSISTENCE));
	    outboundMessageLog = outboundMessageLogDAO.save(outboundMessageLog);
	    returnOutboundMessageLogBean = new OutboundMessageLogBean();
	    BeanUtils.copyProperties(outboundMessageLog, returnOutboundMessageLogBean);
	    returnOutboundMessageLogBean.setId(outboundMessageLog.getId());
	}
	return returnOutboundMessageLogBean;
    }

}
